package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	Uid        int     `gorm:"type:int;comment:用户id"`
	Gid        int     `gorm:"type:int;comment:商品id"`
	OrderSn    string  `gorm:"type:varchar(40);comment:订单号"`
	GoodsName  string  `gorm:"type:varchar(20);comment:商品名称"`
	GoodsPrice float64 `gorm:"type:decimal(10,2);comment:商品价格"`
	GoodsNum   int     `gorm:"type:int;comment:商品购买数量"`
	PayPrice   float64 `gorm:"type:decimal(10,2);comment:实付价格"`
}

func (Order) TableName() string {
	return "order"
}

func (o *Order) AddOrder() error {
	return DB.Create(&o).Error
}

func (o *Order) FindOrder() (result []Order, err error) {
	err = DB.Find(&result).Error
	if err != nil {
		return nil, err
	}
	return result, nil
}
